﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Etong.Web;
public partial class Setup_setupcolumn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //初始化下拉菜单
            this.listshowtype.DataSource = Enum.GetValues(typeof(ListShowType));
            this.listshowtype.DataBind();
            this.editshowtype.DataSource = Enum.GetValues(typeof(EditShowType));
            this.editshowtype.DataBind();
            this.searchshowtype.DataSource = Enum.GetValues(typeof(SearchShowType));
            this.searchshowtype.DataBind();
            this.editshowrangtype.DataSource = Enum.GetValues(typeof(ValidationDataType));
            this.editshowrangtype.DataBind();
            this.searchrangetype.DataSource = Enum.GetValues(typeof(ValidationDataType));
            this.searchrangetype.DataBind();
            this.searchshowruntype.DataSource = Enum.GetValues(typeof(SearchRunType));
            this.searchshowruntype.DataBind();
            this.listHalign.DataSource = Enum.GetValues(typeof(HorizontalAlign));
            this.listHalign.DataBind();

            string tablename = Request.QueryString["tab"];
            string xmlname = Request.QueryString["xml"];
            string columnname = Request.QueryString["col"];
            string columntype=Request.QueryString["ctype"];
            this.tableName.Text = tablename;
            this.xmlName.Text = xmlname;
            this.back.NavigateUrl = "Columns.aspx?xml="+xmlname+"&tab="+tablename;
            this.columnname.Text = columnname;            
            string path = Server.MapPath("~/configs/tables/" + tablename + "/" + xmlname + ".xml");
            ConfigTable cTab = path.XmlToObj<ConfigTable>();
            ConfigColumns cCol = cTab[columnname];
            if (cCol == null)
            {
                cCol = new ConfigColumns(columnname, columntype);
                cTab.Columns.Add(cCol);
                cTab.ObjToXml(path);
            }
            this.columntype.Text = cCol.ColumnDataType.ToString();

            //读取列表显示相关
            this.isListShow.Checked = cCol.IsListShow;
            this.listshowallowsort.Checked = cCol.ListShowAllowSort;
            this.listHalign.SelectedValue = cCol.ListHAlign.ToString();
            this.listshoworder.Text = cCol.ListShowOrder.ToString();
            this.listshowname.Text = cCol.ListShowName;
            this.listshowtype.SelectedValue = cCol.ListShowType.ToString();
            this.listshowformate.Text = cCol.ListShowFormate;
            this.listshowimgwidth.Text = cCol.ListShowImgWidth;
            this.listshowimgheight.Text = cCol.ListShowImgHeight;
            this.listshowlinkurl.Text = cCol.ListShowLinkUrl;
            this.listlinktarget.Text = cCol.ListShowLinkTarget;
            this.listshowlinkboundfields.Text = cCol.ListShowLinkBoundDataField;
            this.listshowlinktext.Text = cCol.ListShowLinkText;
            this.listshowtruetext.Text = cCol.ListShowBoolLinkTrueText;
            this.listshowfalsetext.Text = cCol.ListShowBoolLinkFalseText;
            this.booldate.Text = cCol.ListShowBoolLinkDateColumnName;
            this.listshowconfirmtext.Text = cCol.ListShowConfirmText;
            this.listshowMaintable.Text = cCol.ListShowForeignTable;
            this.listshowmaintablepk.Text = cCol.ListShowForeignTablePK;
            this.listshowmaintableshowfield.Text = cCol.ListShowForeignTableShowField;
            this.listshowtemplatepath.Text = cCol.ListShowTemplatePath;
            
            //读取编辑相关
            this.isAddShow.Checked = cCol.IsAddShow;
            this.isEditShow.Checked = cCol.IsEditShow;
            this.editshoworder.Text = cCol.EditShowOrder.ToString();
            this.editshowname.Text = cCol.EditShowName;
            this.editshowtype.SelectedValue = cCol.EditShowType.ToString();
            this.addShowDefaultvalue.Text = cCol.AddShowDefaultValue;
            this.editshowtextboxwidth.Text = cCol.EditShowTextBoxWidth;
            this.editshowallowupext.Text = cCol.EditShowAllowUploadExt;
            this.editshowhiddenfrom.Text = cCol.EditShowHiddenFrom;
            this.editshowimgwidth.Text = cCol.EditShowImgWidth;
            this.editshowimgheight.Text = cCol.EditShowImgHeight;
            this.editshowrequired.Checked = cCol.EditShowRequired;
            this.editshowrange.Checked = cCol.EditShowRange;
            this.editshowrangeminvalue.Text = cCol.EditShowRangeMinValue;
            this.editshowrangemaxvalue.Text = cCol.EditShowRangeMaxValue;
            this.editshowrangtype.SelectedValue = cCol.EditShowRangeType.ToString();
            this.editshowregexp.Checked = cCol.EditShowRegExp;
            this.editshowregexptext.Text = cCol.EditShowRegExpText;
            this.editshowregexperrmsg.Text = cCol.EditShowRegExpErrMessage;
            this.editshowsql.Text = cCol.EditShowSqlText;
            this.editshowvalue.Text = cCol.EditShowBindValueField;
            this.editshowtext.Text = cCol.EditShowBindTextField;
            this.editshowtemplate.Text = cCol.EditShowTemplatePath;
            this.editshowtemplatefields.Text = cCol.EditShowTemplateFields;
            this.editshowtemplatevaluesfrom.Text = cCol.EditShowTemplateValuesFrom;
            //读取搜索相关
            this.isSearchShow.Checked = cCol.IsSearchShow;
            this.searchshowtype.SelectedValue = cCol.SearchShowType.ToString();
            this.searchshowname.Text = cCol.SearchShowName;
            this.searchshoworder.Text = cCol.SearchShowOrder.ToString();
            this.searchshowruntype.SelectedValue = cCol.SearchShowRunType.ToString();
            this.searchshowsql.Text = cCol.SearchShowSqlText;
            this.searchshowvalue.Text = cCol.SearchShowBindValueField;
            this.searchshowtextfield.Text = cCol.SearchShowBindTextField;
            this.searchshowrange.Checked = cCol.SearchShowRange;
            this.searchrangetype.SelectedValue = cCol.SearchShowRangeType.ToString();
            this.searchshowrangeminvalue.Text = cCol.SearchShowRangeMinValue;
            this.searchshowrangemaxvalue.Text = cCol.SearchShowRangeMaxValue;
            this.searchshowregexp.Checked = cCol.SearchShowRegExp;
            this.searchshowregexptext.Text = cCol.SearchShowRegExpText;
            this.searchshowregexperrmsg.Text = cCol.SearchShowRegExpErrMessage;
            this.searchshowtemplate.Text = cCol.SearchShowTemplatePath;
            this.searchshowtempfields.Text = cCol.SearchShowTemplateFields;
            this.searchshowtempvaluesfrom.Text = cCol.SearchShowTemplateValuesFrom;
            this.searchshowrunsql.Text = cCol.SearchShowRunSql;
            this.searchshowitemcountperrow.Text = cCol.SearchShowItemCountPerRow.ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string tablename = Request.QueryString["tab"];
        string xmlname = Request.QueryString["xml"];
        string columnname = Request.QueryString["col"];
        string columntype = Request.QueryString["ctype"];
        this.columnname.Text = columnname;
        string path = Server.MapPath("~/configs/tables/" + tablename + "/" + xmlname + ".xml");
        ConfigTable cTab = path.XmlToObj<ConfigTable>();
        ConfigColumns cCol = cTab[columnname];

        //设置列表相关
        cCol.IsListShow = this.isListShow.Checked;
        cCol.ListShowName = this.listshowname.Text;
        int listOrder = 1;
        int.TryParse(this.listshoworder.Text, out listOrder);
        cCol.ListShowOrder = listOrder;
        cCol.ListShowAllowSort = this.listshowallowsort.Checked;
        cCol.ListShowType = (ListShowType)Enum.Parse(typeof(ListShowType), this.listshowtype.SelectedValue);
        cCol.ListHAlign = (HorizontalAlign)Enum.Parse(typeof(HorizontalAlign), this.listHalign.SelectedValue);
        cCol.ListShowFormate = this.listshowformate.Text;
        cCol.ListShowImgWidth = this.listshowimgwidth.Text;
        cCol.ListShowImgHeight = this.listshowimgheight.Text;
        cCol.ListShowLinkUrl = this.listshowlinkurl.Text;
        cCol.ListShowLinkTarget = this.listlinktarget.Text;
        cCol.ListShowLinkBoundDataField = this.listshowlinkboundfields.Text;
        cCol.ListShowLinkText = this.listshowlinktext.Text;
        cCol.ListShowBoolLinkTrueText = this.listshowtruetext.Text;
        cCol.ListShowBoolLinkFalseText = this.listshowfalsetext.Text;
        cCol.ListShowBoolLinkDateColumnName = this.booldate.Text;
        cCol.ListShowConfirmText = this.listshowconfirmtext.Text;
        cCol.ListShowForeignTable = this.listshowMaintable.Text;
        cCol.ListShowForeignTablePK = this.listshowmaintablepk.Text;
        cCol.ListShowForeignTableShowField = this.listshowmaintableshowfield.Text;
        cCol.ListShowTemplatePath = this.listshowtemplatepath.Text;

        //设置编辑相关
        cCol.IsAddShow = this.isAddShow.Checked;
        cCol.IsEditShow = this.isEditShow.Checked;        
        cCol.EditShowName = this.editshowname.Text;
        int editOrder = 1;
        int.TryParse(this.editshoworder.Text, out editOrder);
        cCol.EditShowOrder = editOrder;
        cCol.EditShowType = (EditShowType)Enum.Parse(typeof(EditShowType), this.editshowtype.SelectedValue);
        cCol.AddShowDefaultValue = this.addShowDefaultvalue.Text;
        cCol.EditShowTextBoxWidth = this.editshowtextboxwidth.Text;        
        cCol.EditShowAllowUploadExt = this.editshowallowupext.Text;        
        cCol.EditShowHiddenFrom = this.editshowhiddenfrom.Text;        
        cCol.EditShowImgWidth = this.editshowimgwidth.Text;        
        cCol.EditShowImgHeight = this.editshowimgheight.Text;        
        cCol.EditShowRequired = this.editshowrequired.Checked;        
        cCol.EditShowRange = this.editshowrange.Checked;        
        cCol.EditShowRangeMinValue = this.editshowrangeminvalue.Text;        
        cCol.EditShowRangeMaxValue = this.editshowrangemaxvalue.Text;        
        cCol.EditShowRangeType = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), this.editshowrangtype.SelectedValue);        
        cCol.EditShowRegExp = this.editshowregexp.Checked;        
        cCol.EditShowRegExpText = this.editshowregexptext.Text;        
        cCol.EditShowRegExpErrMessage = this.editshowregexperrmsg.Text;        
        cCol.EditShowSqlText = this.editshowsql.Text;
        cCol.EditShowBindValueField = this.editshowvalue.Text;
        cCol.EditShowBindTextField = this.editshowtext.Text;
        cCol.EditShowTemplatePath = this.editshowtemplate.Text;
        cCol.EditShowTemplateFields = this.editshowtemplatefields.Text;
        cCol.EditShowTemplateValuesFrom = this.editshowtemplatevaluesfrom.Text;
        //设置搜索相关
        cCol.IsSearchShow = this.isSearchShow.Checked;
        cCol.SearchShowName = this.searchshowname.Text;
        int searchOrder = 1;
        int.TryParse(this.searchshoworder.Text, out searchOrder);
        cCol.SearchShowType = (SearchShowType)Enum.Parse(typeof(SearchShowType), this.searchshowtype.SelectedValue);
        cCol.SearchShowOrder = searchOrder;
        cCol.SearchShowRunType = (SearchRunType)Enum.Parse(typeof(SearchRunType), this.searchshowruntype.SelectedValue);
        cCol.SearchShowSqlText = this.searchshowsql.Text;
        cCol.SearchShowBindValueField = this.searchshowvalue.Text;
        cCol.SearchShowBindTextField = this.searchshowtextfield.Text;
        cCol.SearchShowRange = this.searchshowrange.Checked;        
        cCol.SearchShowRangeType = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), this.searchrangetype.SelectedValue);
        cCol.SearchShowRangeMinValue = this.searchshowrangeminvalue.Text;
        cCol.SearchShowRangeMaxValue = this.searchshowrangemaxvalue.Text;
        cCol.SearchShowRegExp = this.searchshowregexp.Checked;
        cCol.SearchShowRegExpText = this.searchshowregexptext.Text;
        cCol.SearchShowRegExpErrMessage = this.searchshowregexperrmsg.Text;
        cCol.SearchShowTemplatePath = this.searchshowtemplate.Text;
        cCol.SearchShowTemplateFields = this.searchshowtempfields.Text;
        cCol.SearchShowTemplateValuesFrom = this.searchshowtempvaluesfrom.Text;
        cCol.SearchShowRunSql = this.searchshowrunsql.Text;
        int searchshowitemcountperrow = 5;
        int.TryParse(this.searchshowitemcountperrow.Text, out searchshowitemcountperrow);
        cCol.SearchShowItemCountPerRow = searchshowitemcountperrow;
        //保存
        cTab.ObjToXml(path);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string tablename = Request.QueryString["tab"];
        string xmlname = Request.QueryString["xml"];
        ConfigTable cTab = ConfigTable.GetConfigTable(tablename, xmlname);
        this.listshowlinkurl.Text = "setbool.ashx?tab=" + this.tableName.Text + "&xml=" + this.xmlName.Text + "&col=" + this.columnname.Text + "&id={0}";        
        this.listshowlinkboundfields.Text = cTab.PkFiledName;

    }
}
